#include <iostream>
#include <algorithm>
using namespace std;

int main()
{
    int n;
    cin >> n;
    int ans = 0, min_price = 0x3f3f3f;
    int day_prices;
    for (int i = 0; i < n; i++)
    {
        cin >> day_prices;
        ans = max(ans, day_prices - min_price);
        min_price = min(min_price, day_prices);
    }

    cout << ans << endl;
    return 0;
}